/**
 * 
 */
package server.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * @author Christian
 * 
 */
public class ServerConfig {
	
	private static Logger logger = Logger.getLogger(ServerConfig.class);
	
	private static ServerConfig config = null;
	
	private static File configPath = new File("serverConfigLocal.cfg");
	
	private int rmiRegistryPort = 0;
	
	private String rmiRegistryIp = null;
	
	private String rmiServerHostname = null;
	
	private int rmiServerPort = 0;
	
	private String dbName = null;
	
	private String dbHost = null;
	
	private String dbUserName = null;
	
	private String dbPassword = null;
	
	private int dbConnectionPoolSize = 0;
	
	private int onlineCheckTimerOut = 0;
	
	private boolean loggen = false;
	
	private boolean debug = false;

	private int smsThreadsAnzahl;

	private String vlcPfad;

	private String nircmdPfad;
	
	private String smskey = "";
	
	public static ServerConfig getInstance() {

		if (config == null) {
			logger.error("Config nicht korrekt geladen");
			throw new NullPointerException("Config nicht korrekt geladen");
		}
		return config;
	}
	
	public ServerConfig(String configPathString) throws IOException {

		if (configPathString != null) {
			configPath = new File(configPathString);
		}
		Properties prop = new Properties();
		FileInputStream fis;
		fis = new FileInputStream(configPath);
		prop.load(fis);
		fis.close();
		rmiRegistryPort = Integer.parseInt(prop.getProperty("rmi_registry_port"));
		rmiRegistryIp = prop.getProperty("rmi_registry_ip");
		rmiServerHostname = prop.getProperty("rmi_server_hostname");
		rmiServerPort = Integer.parseInt(prop.getProperty("rmi_server_port"));
		dbName = prop.getProperty("db_name");
		dbHost = prop.getProperty("db_host");
		dbUserName = prop.getProperty("db_username");
		dbPassword = prop.getProperty("db_password");
		dbConnectionPoolSize = Integer.parseInt(prop.getProperty("db_connection_pool_size"));
		loggen = Boolean.parseBoolean(prop.getProperty("loggen"));
		smsThreadsAnzahl = Integer.parseInt(prop.getProperty("smsThreadAnzahl"));
		onlineCheckTimerOut = Integer.parseInt(prop.getProperty("onlineCheckTimer"));
		debug = Boolean.parseBoolean(prop.getProperty("debug"));
		vlcPfad = prop.getProperty("vlcPfad");
		nircmdPfad = prop.getProperty("nircmdPfad");
		smskey = prop.getProperty("smskey");
		config = this;
	}
	
	/**
	 * @return the rmi_registry_port
	 */
	public int getRmiRegistryPort() {

		return rmiRegistryPort;
	}
	
	/**
	 * @return the rmi_registry_ip
	 */
	public String getRmiRegistryIp() {

		return rmiRegistryIp;
	}
	
	/**
	 * @return the rmi_server_hostname
	 */
	public String getRmiServerHostname() {

		return rmiServerHostname;
	}
	
	public int getRmi_server_port() {

		return rmiServerPort;
	}
	
	/**
	 * @return the dbName
	 */
	public String getDbName() {

		return dbName;
	}
	
	/**
	 * @return the dbHost
	 */
	public String getDbHost() {

		return dbHost;
	}
	
	/**
	 * @return the dbUserName
	 */
	public String getDbUserName() {

		return dbUserName;
	}
	
	/**
	 * @return the dbPassword
	 */
	public String getDbPassword() {

		return dbPassword;
	}
	
	/**
	 * @return the loggen
	 */
	public boolean isLoggen() {

		return loggen;
	}
	
	/**
	 * @return the loggen
	 */
	public boolean isDebug() {

		return debug;
	}

	
	/**
	 * @return the smsThreadsAnzahl
	 */
	public int getSmsThreadsAnzahl() {
	
		return smsThreadsAnzahl;
	}

	
	/**
	 * @param smsThreadsAnzahl the smsThreadsAnzahl to set
	 */
	public void setSmsThreadsAnzahl(int smsThreadsAnzahl) {
	
		this.smsThreadsAnzahl = smsThreadsAnzahl;
	}

	
	/**
	 * @return the vlcPfad
	 */
	public String getVlcPfad() {
	
		return vlcPfad;
	}
	
	/**
	 * @return the nircmdPfad
	 */
	public String getNircmdPfad() {
	
		return nircmdPfad;
	}
	
	public int getConnectionPoolSize() {
		
		return dbConnectionPoolSize;
	}
	
	public String getSMSKey() {
		return smskey;
	}
	
	public int getOnlineCheckTimerOut() {
		return onlineCheckTimerOut;
	}
}
